package com.dc.viewpager

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment

class ViewPagerFragment: Fragment() {

    private var content: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            content = it.getString(ARG_CONTENT)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_vp, container, false).apply {
            initView(this)
        }
    }

    private fun initView(view: View) {
        view.findViewById<TextView>(R.id.tv).text = content ?: "NULL"
    }

    companion object {
        private const val ARG_CONTENT = "content"
        fun newInstance(content: String): ViewPagerFragment {
            return ViewPagerFragment().apply {
                val bundle = Bundle()
                bundle.putString(ARG_CONTENT, content)
                arguments = bundle
            }
        }
    }
}